import notfound from '../page/404.vue'
import admin from '../page/admin.vue'
import login from '../page/login.vue'
import product from '../components/product.vue'
import category from '../components/category.vue'
import dashboard from '../components/dashboard.vue'
import tinyMce from '../components/tinymce.vue'
import banner from '../components/banner.vue'
import addBanner from '../components/addBanner.vue'
import echarts from '../components/Echarts.vue'
const routes = [
    {
        path:'/404',
        name:'404',
        component:notfound
    },
    {
        path:'/login',
        alias:'/',
        component:login,
        name:'login'
    },
    {
        path:'/admin',
        component:admin,
        name:'admin',
        redirect:'/admin/dashboard',
        meta:{title:"dashboard"},
        // 进行路由守卫 如果不存在token 则不允许进入admin
        beforeEnter(){
            if(!localStorage.getItem('token')){
                return {name:'login'}
            }
        },
        children:[
            {
                path:'dashboard',
                name:'dashboard',
                meta:{title:"dashboard"},
                component:dashboard
            },
            {
                path:'list',
                name:'list',
                meta:{title:'产品管理'},
                redirect:'/admin/list/product',
                children:[
                    {
                        path:'product',
                        name:"product",
                        meta:{title:"产品列表"},
                        component:product
                    },
                    {
                        path:'category',
                        name:'category',
                        component:category,
                        meta:{title:"分类列表"}
                    },
                ]
            },
            {
                path:'lbt',
                name:'lbt',
                meta:{title:'轮播图管理'},
                redirect:'/admin/lbt/child1',
                children:[
                    {
                        path:'child1',
                        name:"child1",
                        meta:{title:'首页轮播图'},
                        component:banner
                    },
                    {
                        path:'child2',
                        name:'child2',
                        meta:{title:"添加轮播图"},
                        component:addBanner
                    }
                ]
            },
            {
                path:'ksh',
                name:'ksh',
                meta:{title:"数据可视化"},
                redirect:"/admin/ksh/echarts",
                children:[
                    {
                        path:'echarts',
                        name:'echarts',
                        component:echarts,
                        meta:{title:"Echarts"}
                    }
                ]
            },
            {
                path:"fwb",
                name:'fwb',
                meta:{title:"富文本编辑器"},
                redirect:"/admin/fwb/tinymce",
                children:[
                    {
                        path:'tinymce',
                        name:'tinymce',
                        meta:{title:"tinymce"},
                        component:tinyMce
                    }
                ]
            },

        ]
    }
]

export default routes